/*! \file
 * \brief Empty.
 * \author Ivo Wingelaar
 * \date 2011
 * \version 0.1.0
 * \copyright GNU Lesser General Public License v3
 */

#include "MythRandom_AlgorithmSFMT_C.hpp"

namespace Myth
{
namespace Random
{

// Subfunction for the sfmt algorithm
static inline __m128i sfmt_recursion_607(__m128i const &a,
                                     __m128i const &b,
                                     __m128i const &c,
                                     __m128i const &d,
                                     __m128i const &mask)
{
    __m128i a1, b1, c1, d1, z1, z2;
    b1 = _mm_srli_epi32(b, 13);
    a1 = _mm_slli_si128(a, 3);
    c1 = _mm_srli_si128(c, 3);
    d1 = _mm_slli_epi32(d, 15);
    b1 = _mm_and_si128(b1, mask);
    z1 = _mm_xor_si128(a, a1);
    z2 = _mm_xor_si128(b1, d1);
    z1 = _mm_xor_si128(z1, c1);
    z2 = _mm_xor_si128(z1, z2);
    return z2;
}

// Subfunction for the sfmt algorithm
static inline __m128i sfmt_recursion_1279(__m128i const &a,
                                     __m128i const &b,
                                     __m128i const &c,
                                     __m128i const &d,
                                     __m128i const &mask)
{
    __m128i a1, b1, c1, d1, z1, z2;
    b1 = _mm_srli_epi32(b, 5);
    a1 = _mm_slli_si128(a, 3);
    c1 = _mm_srli_si128(c, 1);
    d1 = _mm_slli_epi32(d, 14);
    b1 = _mm_and_si128(b1, mask);
    z1 = _mm_xor_si128(a, a1);
    z2 = _mm_xor_si128(b1, d1);
    z1 = _mm_xor_si128(z1, c1);
    z2 = _mm_xor_si128(z1, z2);
    return z2;
}

// Subfunction for the sfmt algorithm
static inline __m128i sfmt_recursion_2281(__m128i const &a,
                                     __m128i const &b,
                                     __m128i const &c,
                                     __m128i const &d,
                                     __m128i const &mask)
{
    __m128i a1, b1, c1, d1, z1, z2;
    b1 = _mm_srli_epi32(b, 1);
    a1 = _mm_slli_si128(a, 1);
    c1 = _mm_srli_si128(c, 5);
    d1 = _mm_slli_epi32(d, 19);
    b1 = _mm_and_si128(b1, mask);
    z1 = _mm_xor_si128(a, a1);
    z2 = _mm_xor_si128(b1, d1);
    z1 = _mm_xor_si128(z1, c1);
    z2 = _mm_xor_si128(z1, z2);
    return z2;
}

// Subfunction for the sfmt algorithm
static inline __m128i sfmt_recursion_4253(__m128i const &a,
                                     __m128i const &b,
                                     __m128i const &c,
                                     __m128i const &d,
                                     __m128i const &mask)
{
    __m128i a1, b1, c1, d1, z1, z2;
    b1 = _mm_srli_epi32(b, 7);
    a1 = _mm_slli_si128(a, 1);
    c1 = _mm_srli_si128(c, 1);
    d1 = _mm_slli_epi32(d, 20);
    b1 = _mm_and_si128(b1, mask);
    z1 = _mm_xor_si128(a, a1);
    z2 = _mm_xor_si128(b1, d1);
    z1 = _mm_xor_si128(z1, c1);
    z2 = _mm_xor_si128(z1, z2);
    return z2;
}

// Subfunction for the sfmt algorithm
static inline __m128i sfmt_recursion_11213(__m128i const &a,
                                     __m128i const &b,
                                     __m128i const &c,
                                     __m128i const &d,
                                     __m128i const &mask)
{
    __m128i a1, b1, c1, d1, z1, z2;
    b1 = _mm_srli_epi32(b, 7);
    a1 = _mm_slli_si128(a, 3);
    c1 = _mm_srli_si128(c, 3);
    d1 = _mm_slli_epi32(d, 14);
    b1 = _mm_and_si128(b1, mask);
    z1 = _mm_xor_si128(a, a1);
    z2 = _mm_xor_si128(b1, d1);
    z1 = _mm_xor_si128(z1, c1);
    z2 = _mm_xor_si128(z1, z2);
    return z2;
}

// Subfunction for the sfmt algorithm
static inline __m128i sfmt_recursion_19937(__m128i const &a,
                                     __m128i const &b,
                                     __m128i const &c,
                                     __m128i const &d,
                                     __m128i const &mask)
{
    __m128i a1, b1, c1, d1, z1, z2;
    b1 = _mm_srli_epi32(b, 11);
    a1 = _mm_slli_si128(a, 1);
    c1 = _mm_srli_si128(c, 1);
    d1 = _mm_slli_epi32(d, 18);
    b1 = _mm_and_si128(b1, mask);
    z1 = _mm_xor_si128(a, a1);
    z2 = _mm_xor_si128(b1, d1);
    z1 = _mm_xor_si128(z1, c1);
    z2 = _mm_xor_si128(z1, z2);
    return z2;
}

// Subfunction for the sfmt algorithm
static inline __m128i sfmt_recursion_44497(__m128i const &a,
                                     __m128i const &b,
                                     __m128i const &c,
                                     __m128i const &d,
                                     __m128i const &mask)
{
    __m128i a1, b1, c1, d1, z1, z2;
    b1 = _mm_srli_epi32(b, 9);
    a1 = _mm_slli_si128(a, 3);
    c1 = _mm_srli_si128(c, 3);
    d1 = _mm_slli_epi32(d, 5);
    b1 = _mm_and_si128(b1, mask);
    z1 = _mm_xor_si128(a, a1);
    z2 = _mm_xor_si128(b1, d1);
    z1 = _mm_xor_si128(z1, c1);
    z2 = _mm_xor_si128(z1, z2);
    return z2;
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT607_C::AlgorithmSFMT607_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT607_C::~AlgorithmSFMT607_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT607_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 5*4; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xfdff37ff, 0xef7f3f7d, 0xff777b7d, 0x7ff7fb2f};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {0x00000001, 0x00000000, 0x00000000, 0x5986f054};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT607_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 5*4)
        generate();

    y = ((uint32_t*)mState)[mIx++];
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT607_C::get_random_int( int32_t min,
                                              int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT607_C::get_random_double(void)
{
    if(mIx >= 5*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT607_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[5 - 2];
    r2 = mState[5 - 1];
    for(i = 0; i < 5 - 2; i++)
    {
        r = sfmt_recursion_607(mState[i], mState[i + 2], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 5; i++)
    {
        r = sfmt_recursion_607(mState[i], mState[i + 2 - 5], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT1279_C::AlgorithmSFMT1279_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT1279_C::~AlgorithmSFMT1279_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT1279_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 10*4; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xf7fefffd, 0x7fefcfff, 0xaff3ef3f, 0xb5ffff7f};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {0x00000001, 0x00000000, 0x00000000, 0x20000000};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT1279_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 10*4)
        generate();

    y = ((uint32_t*)mState)[mIx++];
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT1279_C::get_random_int( int32_t min,
                                               int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT1279_C::get_random_double(void)
{
    if(mIx >= 10*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT1279_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[10 - 2];
    r2 = mState[10 - 1];
    for(i = 0; i < 10 - 7; i++)
    {
        r = sfmt_recursion_1279(mState[i], mState[i + 7], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 10; i++)
    {
        r = sfmt_recursion_1279(mState[i], mState[i + 7 - 10], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT2281_C::AlgorithmSFMT2281_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT2281_C::~AlgorithmSFMT2281_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT2281_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 18*4; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xbff7ffbf, 0xfdfffffe, 0xf7ffef7f, 0xf2f7cbbf};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {0x00000001, 0x00000000, 0x00000000, 0x41dfa600};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT2281_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 18*4)
        generate();

    y = ((uint32_t*)mState)[mIx++];
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT2281_C::get_random_int( int32_t min,
                                               int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT2281_C::get_random_double(void)
{
    if(mIx >= 18*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT2281_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[18 - 2];
    r2 = mState[18 - 1];
    for(i = 0; i < 18 - 12; i++)
    {
        r = sfmt_recursion_2281(mState[i], mState[i + 12], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 18; i++)
    {
        r = sfmt_recursion_2281(mState[i], mState[i + 12 - 18], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT4253_C::AlgorithmSFMT4253_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT4253_C::~AlgorithmSFMT4253_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT4253_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 34*4; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0x9f7bffff, 0x9fffff5f, 0x3efffffb, 0xfffff7bb};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {0xa8000001, 0xaf5390a3, 0xb740b3f8, 0x6c11486d};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT4253_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 34*4)
        generate();

    y = ((uint32_t*)mState)[mIx++];
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT4253_C::get_random_int( int32_t min,
                                               int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT4253_C::get_random_double(void)
{
    if(mIx >= 34*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT4253_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[34 - 2];
    r2 = mState[34 - 1];
    for(i = 0; i < 34 - 17; i++)
    {
        r = sfmt_recursion_4253(mState[i], mState[i + 17], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 34; i++)
    {
        r = sfmt_recursion_4253(mState[i], mState[i + 17 - 34], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT11213_C::AlgorithmSFMT11213_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT11213_C::~AlgorithmSFMT11213_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT11213_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 88*4; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xeffff7fb,0xffffffef,0xdfdfbfff,0x7fffdbfd};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {1,0,0xe8148000,0xd0c7afa3};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT11213_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 88*4)
        generate();

    y = ((uint32_t*)mState)[mIx++];
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT11213_C::get_random_int( int32_t min,
                                                int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT11213_C::get_random_double(void)
{
    if(mIx >= 88*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT11213_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[88 - 2];
    r2 = mState[88 - 1];
    for(i = 0; i < 88 - 68; i++)
    {
        r = sfmt_recursion_11213(mState[i], mState[i + 68], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 88; i++)
    {
        r = sfmt_recursion_11213(mState[i], mState[i + 68 - 88], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT19937_C::AlgorithmSFMT19937_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT19937_C::~AlgorithmSFMT19937_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT19937_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 156*4; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xdfffffef,0xddfecb7f,0xbffaffff,0xbffffff6};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {1,0,0,0x13c9e684};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT19937_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 156*4)
        generate();

    y = ((uint32_t*)mState)[mIx++];
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT19937_C::get_random_int( int32_t min,
                                                int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT19937_C::get_random_double(void)
{
    if(mIx >= 156*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT19937_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[156 - 2];
    r2 = mState[156 - 1];
    for(i = 0; i < 156 - 122; i++)
    {
        r = sfmt_recursion_19937(mState[i], mState[i + 122], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 156; i++)
    {
        r = sfmt_recursion_19937(mState[i], mState[i + 122 - 156], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT44497_C::AlgorithmSFMT44497_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT44497_C::~AlgorithmSFMT44497_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT44497_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 348*4; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xeffffffb,0xdfbebfff,0xbfbf7bef,0x9ffd7bff};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {1,0,0xa3ac4000,0xecc1327a};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT44497_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 348*4)
        generate();

    y = ((uint32_t*)mState)[mIx++];
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT44497_C::get_random_int( int32_t min,
                                                int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT44497_C::get_random_double(void)
{
    if(mIx >= 348*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT44497_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[348 - 2];
    r2 = mState[348 - 1];
    for(i = 0; i < 348 - 330; i++)
    {
        r = sfmt_recursion_44497(mState[i], mState[i + 330], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 348; i++)
    {
        r = sfmt_recursion_44497(mState[i], mState[i + 330 - 348], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT607_MOA_C::AlgorithmSFMT607_MOA_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT607_MOA_C::~AlgorithmSFMT607_MOA_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT607_MOA_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 5*4 + 5; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xfdff37ff, 0xef7f3f7d, 0xff777b7d, 0x7ff7fb2f};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {0x00000001, 0x00000000, 0x00000000, 0x5986f054};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT607_MOA_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 5*4)
        generate();

    y = ((uint32_t*)mState)[mIx++] + mother_bits();
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT607_MOA_C::get_random_int( int32_t min,
                                                  int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT607_MOA_C::get_random_double(void)
{
    if(mIx >= 5*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    uint64_t r2 = (uint64_t)mother_bits() << 32;
    r2 |= (mMotherState[4] << 16) | (mMotherState[4] >> 16);
    r += r2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT607_MOA_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[5 - 2];
    r2 = mState[5 - 1];
    for(i = 0; i < 5 - 2; i++)
    {
        r = sfmt_recursion_607(mState[i], mState[i + 2], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 5; i++)
    {
        r = sfmt_recursion_607(mState[i], mState[i + 2 - 5], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** function    **/
/** mother_bits **/
//! Get random bits from the mother-of-all generator.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT607_MOA_C::mother_bits(void)
{
   uint64_t sum;
   sum =
      (uint64_t)2111111111U * (uint64_t)mMotherState[3] +
      (uint64_t)1492 * (uint64_t)mMotherState[2] +
      (uint64_t)1776 * (uint64_t)mMotherState[1] +
      (uint64_t)5115 * (uint64_t)mMotherState[0] +
      (uint64_t)mMotherState[4];
   mMotherState[3] = mMotherState[2];
   mMotherState[2] = mMotherState[1];
   mMotherState[1] = mMotherState[0];
   mMotherState[4] = (uint32_t)(sum >> 32);
   mMotherState[0] = (uint32_t)sum;
   return mMotherState[0];
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT1279_MOA_C::AlgorithmSFMT1279_MOA_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT1279_MOA_C::~AlgorithmSFMT1279_MOA_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT1279_MOA_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 10*4 + 5; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xf7fefffd, 0x7fefcfff, 0xaff3ef3f, 0xb5ffff7f};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {0x00000001, 0x00000000, 0x00000000, 0x20000000};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT1279_MOA_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 10*4)
        generate();

    y = ((uint32_t*)mState)[mIx++] + mother_bits();
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT1279_MOA_C::get_random_int( int32_t min,
                                                  int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT1279_MOA_C::get_random_double(void)
{
    if(mIx >= 10*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    uint64_t r2 = (uint64_t)mother_bits() << 32;
    r2 |= (mMotherState[4] << 16) | (mMotherState[4] >> 16);
    r += r2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT1279_MOA_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[10 - 2];
    r2 = mState[10 - 1];
    for(i = 0; i < 10 - 7; i++)
    {
        r = sfmt_recursion_1279(mState[i], mState[i + 7], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 10; i++)
    {
        r = sfmt_recursion_1279(mState[i], mState[i + 7 - 10], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** function    **/
/** mother_bits **/
//! Get random bits from the mother-of-all generator.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT1279_MOA_C::mother_bits(void)
{
   uint64_t sum;
   sum =
      (uint64_t)2111111111U * (uint64_t)mMotherState[3] +
      (uint64_t)1492 * (uint64_t)mMotherState[2] +
      (uint64_t)1776 * (uint64_t)mMotherState[1] +
      (uint64_t)5115 * (uint64_t)mMotherState[0] +
      (uint64_t)mMotherState[4];
   mMotherState[3] = mMotherState[2];
   mMotherState[2] = mMotherState[1];
   mMotherState[1] = mMotherState[0];
   mMotherState[4] = (uint32_t)(sum >> 32);
   mMotherState[0] = (uint32_t)sum;
   return mMotherState[0];
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT2281_MOA_C::AlgorithmSFMT2281_MOA_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT2281_MOA_C::~AlgorithmSFMT2281_MOA_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT2281_MOA_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 18*4 + 5; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xbff7ffbf, 0xfdfffffe, 0xf7ffef7f, 0xf2f7cbbf};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {0x00000001, 0x00000000, 0x00000000, 0x41dfa600};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT2281_MOA_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 18*4)
        generate();

    y = ((uint32_t*)mState)[mIx++] + mother_bits();
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT2281_MOA_C::get_random_int( int32_t min,
                                                  int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT2281_MOA_C::get_random_double(void)
{
    if(mIx >= 18*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    uint64_t r2 = (uint64_t)mother_bits() << 32;
    r2 |= (mMotherState[4] << 16) | (mMotherState[4] >> 16);
    r += r2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT2281_MOA_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[18 - 2];
    r2 = mState[18 - 1];
    for(i = 0; i < 18 - 12; i++)
    {
        r = sfmt_recursion_2281(mState[i], mState[i + 12], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 18; i++)
    {
        r = sfmt_recursion_2281(mState[i], mState[i + 12 - 18], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** function    **/
/** mother_bits **/
//! Get random bits from the mother-of-all generator.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT2281_MOA_C::mother_bits(void)
{
   uint64_t sum;
   sum =
      (uint64_t)2111111111U * (uint64_t)mMotherState[3] +
      (uint64_t)1492 * (uint64_t)mMotherState[2] +
      (uint64_t)1776 * (uint64_t)mMotherState[1] +
      (uint64_t)5115 * (uint64_t)mMotherState[0] +
      (uint64_t)mMotherState[4];
   mMotherState[3] = mMotherState[2];
   mMotherState[2] = mMotherState[1];
   mMotherState[1] = mMotherState[0];
   mMotherState[4] = (uint32_t)(sum >> 32);
   mMotherState[0] = (uint32_t)sum;
   return mMotherState[0];
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT4253_MOA_C::AlgorithmSFMT4253_MOA_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT4253_MOA_C::~AlgorithmSFMT4253_MOA_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT4253_MOA_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 34*4 + 5; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0x9f7bffff, 0x9fffff5f, 0x3efffffb, 0xfffff7bb};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {0xa8000001, 0xaf5390a3, 0xb740b3f8, 0x6c11486d};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT4253_MOA_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 34*4)
        generate();

    y = ((uint32_t*)mState)[mIx++] + mother_bits();
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT4253_MOA_C::get_random_int( int32_t min,
                                                  int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT4253_MOA_C::get_random_double(void)
{
    if(mIx >= 34*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    uint64_t r2 = (uint64_t)mother_bits() << 32;
    r2 |= (mMotherState[4] << 16) | (mMotherState[4] >> 16);
    r += r2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT4253_MOA_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[34 - 2];
    r2 = mState[34 - 1];
    for(i = 0; i < 34 - 17; i++)
    {
        r = sfmt_recursion_4253(mState[i], mState[i + 17], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 34; i++)
    {
        r = sfmt_recursion_4253(mState[i], mState[i + 17 - 34], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** function    **/
/** mother_bits **/
//! Get random bits from the mother-of-all generator.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT4253_MOA_C::mother_bits(void)
{
   uint64_t sum;
   sum =
      (uint64_t)2111111111U * (uint64_t)mMotherState[3] +
      (uint64_t)1492 * (uint64_t)mMotherState[2] +
      (uint64_t)1776 * (uint64_t)mMotherState[1] +
      (uint64_t)5115 * (uint64_t)mMotherState[0] +
      (uint64_t)mMotherState[4];
   mMotherState[3] = mMotherState[2];
   mMotherState[2] = mMotherState[1];
   mMotherState[1] = mMotherState[0];
   mMotherState[4] = (uint32_t)(sum >> 32);
   mMotherState[0] = (uint32_t)sum;
   return mMotherState[0];
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT11213_MOA_C::AlgorithmSFMT11213_MOA_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT11213_MOA_C::~AlgorithmSFMT11213_MOA_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT11213_MOA_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 88*4 + 5; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xeffff7fb,0xffffffef,0xdfdfbfff,0x7fffdbfd};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {1,0,0xe8148000,0xd0c7afa3};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT11213_MOA_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 88*4)
        generate();

    y = ((uint32_t*)mState)[mIx++] + mother_bits();
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT11213_MOA_C::get_random_int( int32_t min,
                                                  int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT11213_MOA_C::get_random_double(void)
{
    if(mIx >= 88*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    uint64_t r2 = (uint64_t)mother_bits() << 32;
    r2 |= (mMotherState[4] << 16) | (mMotherState[4] >> 16);
    r += r2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT11213_MOA_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[88 - 2];
    r2 = mState[88 - 1];
    for(i = 0; i < 88 - 68; i++)
    {
        r = sfmt_recursion_11213(mState[i], mState[i + 68], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 88; i++)
    {
        r = sfmt_recursion_11213(mState[i], mState[i + 68 - 88], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** function    **/
/** mother_bits **/
//! Get random bits from the mother-of-all generator.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT11213_MOA_C::mother_bits(void)
{
   uint64_t sum;
   sum =
      (uint64_t)2111111111U * (uint64_t)mMotherState[3] +
      (uint64_t)1492 * (uint64_t)mMotherState[2] +
      (uint64_t)1776 * (uint64_t)mMotherState[1] +
      (uint64_t)5115 * (uint64_t)mMotherState[0] +
      (uint64_t)mMotherState[4];
   mMotherState[3] = mMotherState[2];
   mMotherState[2] = mMotherState[1];
   mMotherState[1] = mMotherState[0];
   mMotherState[4] = (uint32_t)(sum >> 32);
   mMotherState[0] = (uint32_t)sum;
   return mMotherState[0];
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT19937_MOA_C::AlgorithmSFMT19937_MOA_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT19937_MOA_C::~AlgorithmSFMT19937_MOA_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT19937_MOA_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 156*4 + 5; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xdfffffef,0xddfecb7f,0xbffaffff,0xbffffff6};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {1,0,0,0x13c9e684};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT19937_MOA_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 156*4)
        generate();

    y = ((uint32_t*)mState)[mIx++] + mother_bits();
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT19937_MOA_C::get_random_int( int32_t min,
                                                  int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT19937_MOA_C::get_random_double(void)
{
    if(mIx >= 156*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    uint64_t r2 = (uint64_t)mother_bits() << 32;
    r2 |= (mMotherState[4] << 16) | (mMotherState[4] >> 16);
    r += r2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT19937_MOA_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[156 - 2];
    r2 = mState[156 - 1];
    for(i = 0; i < 156 - 122; i++)
    {
        r = sfmt_recursion_19937(mState[i], mState[i + 122], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 156; i++)
    {
        r = sfmt_recursion_19937(mState[i], mState[i + 122 - 156], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** function    **/
/** mother_bits **/
//! Get random bits from the mother-of-all generator.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT19937_MOA_C::mother_bits(void)
{
   uint64_t sum;
   sum =
      (uint64_t)2111111111U * (uint64_t)mMotherState[3] +
      (uint64_t)1492 * (uint64_t)mMotherState[2] +
      (uint64_t)1776 * (uint64_t)mMotherState[1] +
      (uint64_t)5115 * (uint64_t)mMotherState[0] +
      (uint64_t)mMotherState[4];
   mMotherState[3] = mMotherState[2];
   mMotherState[2] = mMotherState[1];
   mMotherState[1] = mMotherState[0];
   mMotherState[4] = (uint32_t)(sum >> 32);
   mMotherState[0] = (uint32_t)sum;
   return mMotherState[0];
}

/** constructor **/
/// \param   int32_t seed
///         The seed you want to initialize the generator with.
AlgorithmSFMT44497_MOA_C::AlgorithmSFMT44497_MOA_C( int32_t seed) :
    mLastInterval(0)
{
    random_init(seed);
}

/** default destructor **/
AlgorithmSFMT44497_MOA_C::~AlgorithmSFMT44497_MOA_C()
{
    //
}

/** virtual function **/
/** random_init      **/
//! Initializes the generator with a new seed.
/// \return void
/// \param   int32_t seed
///         The seed to initialize the generator with.
void AlgorithmSFMT44497_MOA_C::random_init( int32_t seed)
{
    uint32_t y = seed;
    ((uint32_t*)mState)[0] = y;

    for(uint32_t i = 1; i < 348*4 + 5; i++)
    {
        y = 1812433253U * (y ^ (y >> 30)) + i;
        ((uint32_t*)mState)[i] = y;
    }

    uint32_t i, j;

    static const uint32_t maskinit[4] = {0xeffffffb,0xdfbebfff,0xbfbf7bef,0x9ffd7bff};
    mMask = _mm_loadu_si128((__m128i*)maskinit);

    static const uint32_t parityvec[4] = {1,0,0xa3ac4000,0xecc1327a};

    uint32_t temp = 0;
    for(i = 0; i < 4; i++)
        temp ^= parityvec[i] & ((uint32_t*)mState)[i];

    for(i = 16; i > 0; i >>= 1)
        temp ^= temp >> i;

    if(!(temp & 1))
    {
        for(i = 0; i < 4; i++)
        {
            if(parityvec[i])
            {
                for(j = 1; j; j <<= 1)
                {
                    if(parityvec[i] & j)
                    {
                        ((uint32_t*)mState)[i] ^= j;
                        i = 5;
                        break;
                    }
                }
            }
        }
    }
    generate();
}

/** virtual function **/
/** get_random_bytes **/
//! Return 32 random bits.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT44497_MOA_C::get_random_bytes(void)
{
    uint32_t y;

    if(mIx >= 348*4)
        generate();

    y = ((uint32_t*)mState)[mIx++] + mother_bits();
    return y;
}

/** virtual function **/
/** get_random_int   **/
//! Returns a random number in the interval [min, max].
/// \return int32_t
///         A number between min and max (inclusive).
/// \param   int32_t min
///         The smallest number allowed.
/// \param   int32_t max
///         The largest number allowed.
int32_t AlgorithmSFMT44497_MOA_C::get_random_int( int32_t min,
                                                  int32_t max)
{
    if(max <= min)
    {
        if (max == min) return min;
        else return 0x80000000;
    }

    uint32_t iran, remainder;
    uint32_t interval = uint32_t(max - min + 1);

    if(interval != mLastInterval)
    {
        mRLimit = uint32_t(((uint64_t)1 << 32) / interval) * interval - 1;
        mLastInterval = interval;
    }
    do
    {
        uint64_t longran  = (uint64_t)get_random_bytes() * interval;
        iran = (uint32_t)(longran >> 32);
        remainder = (uint32_t)longran;
    }
    while(remainder > mRLimit);

    return (int32_t)iran + min;
}

/** virtual function  **/
/** get_random_double **/
//! Return a random 64 bit floating point value in the interval [0, 1]
/// \return double
///         A random 64 bit float.
/// \param  void
double AlgorithmSFMT44497_MOA_C::get_random_double(void)
{
    if(mIx >= 348*4-1)
        generate();

    uint64_t r = *(uint64_t*)((uint32_t*)mState+mIx);
    mIx += 2;

    uint64_t r2 = (uint64_t)mother_bits() << 32;
    r2 |= (mMotherState[4] << 16) | (mMotherState[4] >> 16);
    r += r2;

    return (int64_t)(r >> 12) * (1./(67108864.0*67108864.0));
}

/** function **/
/** generate **/
//! Fill the state array with new random numbers.
/// \return void
/// \param  void
void AlgorithmSFMT44497_MOA_C::generate(void)
{
    int i;
    __m128i r, r1, r2;

    r1 = mState[348 - 2];
    r2 = mState[348 - 1];
    for(i = 0; i < 348 - 330; i++)
    {
        r = sfmt_recursion_44497(mState[i], mState[i + 330], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    for(; i < 348; i++)
    {
        r = sfmt_recursion_44497(mState[i], mState[i + 330 - 348], r1, r2, mMask);
        mState[i] = r;
        r1 = r2;
        r2 = r;
    }
    mIx = 0;
}

/** function    **/
/** mother_bits **/
//! Get random bits from the mother-of-all generator.
/// \return uint32_t
///         32 random bits.
/// \param  void
uint32_t AlgorithmSFMT44497_MOA_C::mother_bits(void)
{
   uint64_t sum;
   sum =
      (uint64_t)2111111111U * (uint64_t)mMotherState[3] +
      (uint64_t)1492 * (uint64_t)mMotherState[2] +
      (uint64_t)1776 * (uint64_t)mMotherState[1] +
      (uint64_t)5115 * (uint64_t)mMotherState[0] +
      (uint64_t)mMotherState[4];
   mMotherState[3] = mMotherState[2];
   mMotherState[2] = mMotherState[1];
   mMotherState[1] = mMotherState[0];
   mMotherState[4] = (uint32_t)(sum >> 32);
   mMotherState[0] = (uint32_t)sum;
   return mMotherState[0];
}

} // namespace Random
} // namespace Myth
